from PIL import Image
def main():
    img_name = ' hellokitty.jpg'
    width, height = 80, 48
    img = Image.open(img_name).resize((width, height)).convert('L')
    text = ''
    for y in range(height):
        for x in range(width):
            text += getchar(img.getpixel((x, y)))
        text += '\n'
    fo = open('hellokitty.txt', 'w')
    fo.write(text)
    fo.close()
ascii_char = list('MNHQ$OC? 7>!:-;. ')
def getchar(gray):
    unit = 256/len(ascii_char)
    return ascii_char[int(gray//unit)]
main()
